# -*- coding: utf-8 -*-

# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://doc.scrapy.org/en/latest/topics/item-pipeline.html

import pymysql
class CsdnPipeline(object):
    def process_item(self, item, spider):
        try:
            conn=pymysql.connect(host="127.0.0.1", user="root", password="root", db="python2", charset="utf8")
            for i in range(0,len(item["courseName"])):
                courseName=item["courseName"][i]
                coursePrice = item["coursePrice"][i]
                courseHour = item["courseHour"][i]
                sql="insert into courses(title,price,hour) values('"+courseName+"','"+coursePrice+"','"+courseHour+"')"
                conn.query(sql)
            conn.close()
        except Exception as err:
            print(err)
        return item
